<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="订单ID" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商家名称" prop="shopName">
        <el-input
          v-model="queryParams.shopName"
          placeholder="请输入商家名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户名称" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入用户名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单类型" prop="orderType">
        <el-select v-model="queryParams.orderType" placeholder="请选择订单类型" clearable size="small">
          <el-option label="用户付费订单" value="1"></el-option>
          <el-option label="商户退款充值订单" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="支付类型" prop="payStatus">
        <el-select v-model="queryParams.payStatus" placeholder="请选择支付类型" clearable size="small">
          <el-option label="未支付" value="0"></el-option>
          <el-option label="部分支付" value="1"></el-option>
          <el-option label="已支付" value="2"></el-option>
          <el-option label="部分退款" value="3"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间" prop="createdTime">
        <el-date-picker clearable size="small"
          v-model="dateRange"
          type="daterange"
          value-format="yyyy-MM-dd"
          start-placeholder="开始时间"
          end-placeholder="结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="list">
      <el-table-column label="订单ID" align="center" prop="order_id" width="100px" />
      <el-table-column label="创建时间" align="center" prop="created_time" width="180px" />
      <el-table-column label="商户" align="center" prop="shop_name" show-overflow-tooltip />
      <el-table-column label="用户" align="center" prop="username" />
      <el-table-column label="金额" align="center" prop="amount" width="260px">
        <template slot-scope="scope">
          <p v-if="scope.row.pay_status === 3">
            <span>{{scope.row.amount - scope.row.refund_amount | currency}} (</span>
            <span style="color: #00a7d0">{{scope.row.msf_channel_fee - scope.row.r_msf_channel_fee | currency}}</span> +
            <span style="color: #0d77e4">{{scope.row.dds_channel_fee - scope.row.r_dds_channel_fee | currency}}</span> +
            <span style="color: #0d6aad">{{scope.row.merchant_fee - scope.row.r_merchant_fee | currency}}</span>）
          </p>
          <p v-else>
            <span>{{scope.row.amount | currency}} (</span>
            <span style="color: #00a7d0">{{scope.row.msf_channel_fee | currency}}</span> +
            <span style="color: #0d77e4">{{scope.row.dds_channel_fee | currency}}</span> +
            <span style="color: #0d6aad">{{scope.row.merchant_fee | currency}}</span>）
          </p>
        </template>
      </el-table-column>
      <el-table-column label="实付金额" align="center" prop="act_pay_amount">
        <template slot-scope="scope">
          <span>{{scope.row.act_pay_amount | currency}}</span>
        </template>
      </el-table-column>
      <el-table-column label="获得积分 / 补贴金额" align="center" prop="score">
        <template slot-scope="scope">
          <p v-if="scope.row.order_method === '1'">{{ scope.row.score }} 分</p>
          <p v-else>{{ scope.row.subsidy | currency}}</p>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="pay_status">
        <template slot-scope="scope">
          <p v-if="scope.row.pay_status === 0">未支付</p>
          <p v-else-if="scope.row.pay_status === 1">部分支付</p>
          <p v-else-if="scope.row.pay_status === 2">已支付</p>
          <p v-else-if="scope.row.pay_status === 3">部分退款</p>
          <p v-else>未知状态</p>
        </template>
      </el-table-column>
      <el-table-column label="订单方式" align="center" prop="order_method">
        <template slot-scope="scope">
          {{ scope.row.order_method === "1" ? "返积分类订单" : "补贴类订单"}}
        </template>
      </el-table-column>
      <el-table-column label="类型" align="center" prop="order_type">
        <template slot-scope="scope">
          {{ scope.row.order_type === "1" ? "用户付费订单" : "商户退款充值订单"}}
        </template>
      </el-table-column>
      <el-table-column label="支付类型" align="center" prop="payment_type">
        <template slot-scope="scope">
          {{ scope.row.payment_type == "05" ? "微信" : "支付宝"}}
        </template>
      </el-table-column>

    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listOrder } from '@/api/union/order'

export default {
  name: 'index',
  data() {
    return {
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: "created_time",
        isAsc: "desc",
        orderId: null,
        shopName: null,
        username: null,
        orderType: null,
        payStatus: null
      },
      showSearch: true,
      loading: true,
      list: [],
      dateRange: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true

      listOrder(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.loading = false
        this.list = response.rows
        this.total = response.total
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRange = []
      this.handleQuery();
    }
  }
}
</script>
